package com.laogao.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestLogController {

    private static final Logger logger = LoggerFactory.getLogger(TestLogController.class);

    @GetMapping("/test")
    public String generateLog() {
        logger.info("Test INFO log message triggered");
        logger.error("Test ERROR log message triggered");
        return "Test logs generated. Check your log viewer!";
    }

    @Scheduled(fixedRate = 1000)
    public String autoGenerateLog() {
        logger.info("Test info log message triggered");
        logger.error("Test error log message triggered");
        logger.warn("Test warn log message triggered");
        logger.debug("Test debug log message triggered");
        int i = 1 / 0;

        int j = 1;
        if (j > 0) {
            throw new RuntimeException("ssss");
        }
        return "Test logs generated. Check your log viewer!";
    }

    @Scheduled(fixedRate = 2000)
    public void autoGenerateLog2() {
        int j = 1;
        if (j > 0) {
            throw new RuntimeException("sssss--------------------------ss");
        }
    }
}
